import ajax from '../js/ajax';

const form = document.forms.login;

form.onsubmit = function (e) {
    e.preventDefault();
    ajax('post', '/api/admin/login', { uid: form.uid.value, pwd: form.pwd.value })
        .then(({ flag, msg, token }) => {
            if (flag) {
                alert(msg);
                localStorage.setItem('token', token);
                location.replace('index.html');
            } else {
                alert(msg);
            }
        })
        .catch(err => {
            alert('服务器忙，请稍后再试');
        })
}